package chap3_6;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author https://gitee.com/W_Jun
 * @date 2021-12-13 20:44
 * @Description 字符流读数据的2种方式
 */
public class InputStreamReaderDemo {
    public static void main(String[] args) throws IOException {
        InputStreamReader isr = new InputStreamReader(new FileInputStream("chapter03-字符流\\osw.txt"));
        //int read()：一次读一个字符
/*
        int ch;
        while ((ch = isr.read()) != -1) {
            System.out.print((char) ch);
        }
        isr.close();
        System.out.println("------");
*/

        //int read(char[] cbuf)：一次读一个字符数组
        int len;
        char[] chs = new char[1024];
        while ((len = isr.read(chs)) != -1) {
            System.out.print(new String(chs, 0, len));
        }
        isr.close();
    }
}
